//
//  ViewController.m
//  MyOpenGLESLearn_iOS
//
//  Created by Gaomingyang on 2021/4/13.
//

#import "ViewController.h"
#import "TriangleController.h"
#import "RectangleController.h"
#import "CircularController.h"
#import "CubeController.h"
#import "ConeController.h"
#import "CylinderController.h"
#import "BallController.h"
#import "BallLightController.h"
#import "PictureController.h"
#import "VaryController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataList;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self commonInit];
}

-(void)commonInit{
    self.title = @"OpenGLES learn";
    self.view.backgroundColor = [UIColor whiteColor];
    [self initDefaultData];
    [self addMySubViews];
    [self addMyContraints];
}
-(void)initDefaultData{
    [self.dataList addObject:@"三角形"];
    [self.dataList addObject:@"长方形"];
    [self.dataList addObject:@"圆形"];
    [self.dataList addObject:@"正方体"];
    [self.dataList addObject:@"圆锥"];
    [self.dataList addObject:@"圆柱"];
    [self.dataList addObject:@"球形"];
    [self.dataList addObject:@"球形带光"];
    [self.dataList addObject:@"图片处理"];
    [self.dataList addObject:@"图形变换"];
    
}
-(void)addMySubViews{
    [self.view addSubview:self.tableView];
}
-(void)addMyContraints{
    CGFloat navHeight =  self.navigationController.navigationBar.bounds.size.height;
    CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
    CGFloat titleHeight = navHeight + rectStatus.size.height;
    self.tableView.frame = CGRectMake(0, titleHeight, self.view.bounds.size.width, self.view.bounds.size.height-titleHeight);
}

//MARK:UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataList.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"MyTableviewCellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }

    cell.textLabel.text = self.dataList[indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"点击了cell，第：%ld 组，第 :%ld 行",(long)indexPath.section,(long)indexPath.row);
    if (indexPath.section == 0 ) {
        if (indexPath.row == 0) {
            [self.navigationController pushViewController:[TriangleController new] animated:YES];
        }else if(indexPath.row == 1){
            [self.navigationController pushViewController:[RectangleController new] animated:YES];
        }else if(indexPath.row == 2){
            [self.navigationController pushViewController:[CircularController new] animated:YES];
        }else if(indexPath.row == 3){
            [self .navigationController pushViewController:[CubeController new] animated:YES];
        }else if(indexPath.row == 4){
            [self .navigationController pushViewController:[ConeController new] animated:YES];
        }else if(indexPath.row == 5){
            [self .navigationController pushViewController:[CylinderController new] animated:YES];
        }else if(indexPath.row == 6){
            [self .navigationController pushViewController:[BallController new] animated:YES];
        }else if(indexPath.row == 7){
            [self .navigationController pushViewController:[BallLightController new] animated:YES];
        }else if(indexPath.row == 8){
            [self .navigationController pushViewController:[PictureController new] animated:YES];
        }else if(indexPath.row == 9){
            [self .navigationController pushViewController:[VaryController new] animated:YES];
        }
    }
}
#pragma mark -- lazy load
- (NSMutableArray *)dataList{
    if (_dataList == nil) {
        _dataList = [NSMutableArray new];
    }
    return _dataList;
}
-(UITableView *)tableView{
    if (_tableView == nil  ) {
        _tableView = [[UITableView alloc] init];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        if (@available(iOS 11.0, *)) {
            _tableView.estimatedRowHeight = 0;
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
//        [_tableView registerClass:[PASEHWiPhoneAllhomeworkCell class] forCellReuseIdentifier:[PASEHWiPhoneAllhomeworkCell getID]];
       
    }
    return _tableView;
}

@end
